Micron Document
πŸŽ–οΈGitΠ―Ρ€Π°πŸŽ–οΈ

Node / meshtastic / Meshtastic-Android / files / core / ui / src / commonMain / kotlin / org / meshtastic / core / ui / util / ProtoExtensions.kt

Displaying Raw β€’ Download

core/ui/src/commonMain/kotlin/org/meshtastic/core/ui/util/ProtoExtensions.kt 01cd54907d62cd90913d3d071b6bc240cae365ef (01cd5490) Text, 16.42 KB

T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.core.ui.util

Tff7b72import T7ee787androidx.compose.runtime.Composable
Tff7b72import T7ee787co.touchlab.kermit.Logger
Tff7b72import T7ee787kotlinx.coroutines.NonCancellable
Tff7b72import T7ee787kotlinx.coroutines.flow.first
Tff7b72import T7ee787kotlinx.coroutines.withContext
Tff7b72import T7ee787okio.ByteString
Tff7b72import T7ee787org.jetbrains.compose.resources.stringResource
Tff7b72import T7ee787org.meshtastic.core.common.util.DateFormatter
Tff7b72import T7ee787org.meshtastic.core.common.util.nowMillis
Tff7b72import T7ee787org.meshtastic.core.repository.RadioConfigRepository
Tff7b72import T7ee787org.meshtastic.core.repository.RadioController
Tff7b72import T7ee787org.meshtastic.core.resources.Res
Tff7b72import T7ee787org.meshtastic.core.resources.unknown_age
Tff7b72import T7ee787org.meshtastic.proto.Channel
Tff7b72import T7ee787org.meshtastic.proto.ChannelSet
Tff7b72import T7ee787org.meshtastic.proto.ChannelSettings
Tff7b72import T7ee787org.meshtastic.proto.Config
Tff7b72import T7ee787org.meshtastic.proto.MeshPacket
Tff7b72import T7ee787org.meshtastic.proto.Position
Tff7b72import T7ee787kotlin.time.Duration.Companion.days
Tff7b72import T7ee787org.meshtastic.core.model.Channel Tff7b72as Te6edf3ModelChannel

Tff7b72private Tff7b72const Tff7b72val Te6edf3SECONDS_TO_MILLIS Tff7b72= T79c0ff1T79c0ff0T79c0ff0T79c0ff0L

T8b949e// Firmware channel files expose eight slots: one primary plus up to seven secondary channels.
Tff7b72private Tff7b72const Tff7b72val Te6edf3CHANNEL_REPLACEMENT_SLOT_COUNT Tff7b72= T79c0ff8

Tf0883e@Composable
Tff7b72fun Te6edf3PositionTb4b4b4.Td2a8ffformatPositionTimeTb4b4b4(Tb4b4b4)Tb4b4b4: Tffa657String Tb4b4b4{
Tff7b72val Te6edf3currentTime Tff7b72= Te6edf3nowMillis
Tff7b72val Te6edf3sixMonthsAgo Tff7b72= Te6edf3currentTime Tff7b72- T79c0ff1T79c0ff8T79c0ff0.Te6edf3daysTb4b4b4.Te6edf3inWholeMilliseconds
Tff7b72val Te6edf3isOlderThanSixMonths Tff7b72= Te6edf3time Tff7b72* Te6edf3SECONDS_TO_MILLIS Tff7b72< Te6edf3sixMonthsAgo
Tff7b72val Te6edf3timeText Tff7b72=
Tff7b72if Tb4b4b4(Te6edf3isOlderThanSixMonthsTb4b4b4) Tb4b4b4{
Te6edf3stringResourceTb4b4b4(Te6edf3ResTb4b4b4.Te6edf3stringTb4b4b4.Te6edf3unknown_ageTb4b4b4)
Tb4b4b4} Tff7b72else Tb4b4b4{
Te6edf3DateFormatterTb4b4b4.Te6edf3formatDateTimeTb4b4b4(Te6edf3time Tff7b72* Te6edf3SECONDS_TO_MILLISTb4b4b4)
Tb4b4b4}
Tff7b72return Te6edf3timeText
Tb4b4b4}

Tff7b72fun Te6edf3MeshPacketTb4b4b4.Td2a8fftoPositionTb4b4b4(Tb4b4b4)Tb4b4b4: Te6edf3Position? Tb4b4b4{
Tff7b72val Te6edf3decoded Tff7b72= Te6edf3decoded Tff7b72?: Tff7b72return Tff7b72null
Tff7b72return Tff7b72if Tb4b4b4(Te6edf3decodedTb4b4b4.Te6edf3want_response Tff7b72!Tff7b72= Tff7b72trueTb4b4b4) Tb4b4b4{
Te6edf3decodedTb4b4b4.Te6edf3payloadTb4b4b4.Te6edf3let Tb4b4b4{ Te6edf3runCatching Tb4b4b4{ Te6edf3PositionTb4b4b4.Te6edf3ADAPTERTb4b4b4.Te6edf3decodeTb4b4b4(Tffa657itTb4b4b4) Tb4b4b4}Tb4b4b4.Te6edf3getOrNullTb4b4b4(Tb4b4b4) Tb4b4b4}
Tb4b4b4} Tff7b72else Tb4b4b4{
Tff7b72null
Tb4b4b4}
Tb4b4b4}

T8b949e/**
* Builds a [Channel] list from the difference between two [ChannelSettings] lists. Only changes are included in the
* resulting list.
*
* @param new The updated [ChannelSettings] list.
* @param old The current [ChannelSettings] list (required when disabling unused channels).
* @return A [Channel] list containing only the modified channels.
*/
Tff7b72fun Td2a8ffgetChannelListTb4b4b4(Te6edf3newTb4b4b4: Te6edf3ListTff7b72<Te6edf3ChannelSettingsTff7b72>Tb4b4b4, Te6edf3oldTb4b4b4: Te6edf3ListTff7b72<Te6edf3ChannelSettingsTff7b72>Tb4b4b4)Tb4b4b4: Te6edf3ListTff7b72<Te6edf3ChannelTff7b72> Tff7b72= Te6edf3buildList Tb4b4b4{
Tff7b72for Tb4b4b4(Te6edf3i Tff7b72in T79c0ff0.Tb4b4b4.Te6edf3maxOfTb4b4b4(Te6edf3oldTb4b4b4.Te6edf3lastIndexTb4b4b4, Te6edf3newTb4b4b4.Te6edf3lastIndexTb4b4b4)Tb4b4b4) Tb4b4b4{
Tff7b72if Tb4b4b4(Te6edf3oldTb4b4b4.Te6edf3getOrNullTb4b4b4(Te6edf3iTb4b4b4) Tff7b72!Tff7b72= Te6edf3newTb4b4b4.Te6edf3getOrNullTb4b4b4(Te6edf3iTb4b4b4)Tb4b4b4) Tb4b4b4{
Te6edf3addTb4b4b4(
Te6edf3ChannelTb4b4b4(
Te6edf3role Tff7b72=
Tff7b72when Tb4b4b4(Te6edf3iTb4b4b4) Tb4b4b4{
T79c0ff0 Tff7b72-Tff7b72> Te6edf3ChannelTb4b4b4.Te6edf3RoleTb4b4b4.Te6edf3PRIMARY
Tff7b72in T79c0ff1.Tb4b4b4.Te6edf3newTb4b4b4.Te6edf3lastIndex Tff7b72-Tff7b72> Te6edf3ChannelTb4b4b4.Te6edf3RoleTb4b4b4.Te6edf3SECONDARY
Tff7b72else Tff7b72-Tff7b72> Te6edf3ChannelTb4b4b4.Te6edf3RoleTb4b4b4.Te6edf3DISABLED
Tb4b4b4}Tb4b4b4,
Te6edf3index Tff7b72= Te6edf3iTb4b4b4,
Te6edf3settings Tff7b72= Te6edf3newTb4b4b4.Te6edf3getOrNullTb4b4b4(Te6edf3iTb4b4b4) Tff7b72?: Te6edf3ChannelSettingsTb4b4b4(Tb4b4b4)Tb4b4b4,
Tb4b4b4)Tb4b4b4,
Tb4b4b4)
Tb4b4b4}
Tb4b4b4}
Tb4b4b4}

T8b949e/**
* Builds an authoritative [Channel] list for a full REPLACE import. Every position in [new] is emitted (PRIMARY at
* index 0, SECONDARY for 1..new.lastIndex) and any trailing positions beyond [new]'s range are emitted as DISABLED so
* the radio stops using them.
*
* Unlike [getChannelList], this does NOT skip positions where `currentSettings[i] == new[i]`: the imported set is
* authoritative, the local cache must not gate the writes, and silent diff-skips during REPLACE were the source of
* stale channels.
*
* [currentSettings] is consulted only for its size (to determine trailing DISABLED writes); its values are never
* compared against [new]. Callers should read it from `radioConfigRepository.channelSetFlow.first().settings`, not from
* a `stateInWhileSubscribed` StateFlow's `.value` β€” the StateFlow placeholder window can return an empty list and
* suppress trailing DISABLED writes.
*
* Edge case: if [new] is empty, every emitted slot (including index 0) is DISABLED rather than wrongly promoting an
* empty [ChannelSettings] to PRIMARY.
*
* @param new The imported [ChannelSettings] list. Every index becomes a write to the radio.
* @param currentSettings The current [ChannelSettings] list. Only its size is used; trailing indices past [new] become
* DISABLED writes so leftover slots are cleared.
* @param minimumSlotCount The minimum slot count to emit. Full replacement callers can use this to disable firmware
* slots even when the local cache is stale or shorter than the radio's actual channel list.
* @param maximumSlotCount The maximum slot count to emit. Full replacement callers use this to avoid unsupported
* firmware channel indices even if an imported or cached list is longer than expected.
* @return A [Channel] list covering every slot the radio needs written to materialize [new] and clear leftover slots.
*/
Tff7b72fun Td2a8ffgetChannelReplacementListTb4b4b4(
Te6edf3newTb4b4b4: Te6edf3ListTff7b72<Te6edf3ChannelSettingsTff7b72>Tb4b4b4,
Te6edf3currentSettingsTb4b4b4: Te6edf3ListTff7b72<Te6edf3ChannelSettingsTff7b72>Tb4b4b4,
Te6edf3minimumSlotCountTb4b4b4: Tffa657Int Tff7b72= T79c0ff0Tb4b4b4,
Te6edf3maximumSlotCountTb4b4b4: Tffa657Int Tff7b72= Tffa657IntTb4b4b4.Te6edf3MAX_VALUETb4b4b4,
Tb4b4b4)Tb4b4b4: Te6edf3ListTff7b72<Te6edf3ChannelTff7b72> Tff7b72= Te6edf3buildList Tb4b4b4{
Te6edf3requireTb4b4b4(Te6edf3minimumSlotCount Tff7b72<Tff7b72= Te6edf3maximumSlotCountTb4b4b4) Tb4b4b4{ Ta5d6ff"Ta5d6ffminimumSlotCount must be <= maximumSlotCountTa5d6ff" Tb4b4b4}
Tff7b72val Te6edf3minimumLastIndex Tff7b72= Te6edf3minimumSlotCountTb4b4b4.Te6edf3coerceAtLeastTb4b4b4(T79c0ff0Tb4b4b4) Tff7b72- T79c0ff1
Tff7b72val Te6edf3maximumLastIndex Tff7b72= Te6edf3maximumSlotCountTb4b4b4.Te6edf3coerceAtLeastTb4b4b4(T79c0ff0Tb4b4b4) Tff7b72- T79c0ff1
Tff7b72val Te6edf3endIndex Tff7b72= Te6edf3maxOfTb4b4b4(Te6edf3currentSettingsTb4b4b4.Te6edf3lastIndexTb4b4b4, Te6edf3newTb4b4b4.Te6edf3lastIndexTb4b4b4, Te6edf3minimumLastIndexTb4b4b4)Tb4b4b4.Te6edf3coerceAtMostTb4b4b4(Te6edf3maximumLastIndexTb4b4b4)
Tff7b72if Tb4b4b4(Te6edf3endIndex Tff7b72< T79c0ff0Tb4b4b4) Tff7b72returnTf0883e@buildList
Tff7b72for Tb4b4b4(Te6edf3i Tff7b72in T79c0ff0.Tb4b4b4.Te6edf3endIndexTb4b4b4) Tb4b4b4{
Te6edf3addTb4b4b4(
Te6edf3ChannelTb4b4b4(
Te6edf3role Tff7b72=
Tff7b72when Tb4b4b4(Te6edf3iTb4b4b4) Tb4b4b4{
T8b949e// Empty-new is a degenerate import: every slot (including 0) must be DISABLED.
T79c0ff0 Tff7b72-Tff7b72> Tff7b72if Tb4b4b4(Te6edf3newTb4b4b4.Te6edf3isEmptyTb4b4b4(Tb4b4b4)Tb4b4b4) Te6edf3ChannelTb4b4b4.Te6edf3RoleTb4b4b4.Te6edf3DISABLED Tff7b72else Te6edf3ChannelTb4b4b4.Te6edf3RoleTb4b4b4.Te6edf3PRIMARY

Tff7b72in T79c0ff1.Tb4b4b4.Te6edf3newTb4b4b4.Te6edf3lastIndex Tff7b72-Tff7b72> Te6edf3ChannelTb4b4b4.Te6edf3RoleTb4b4b4.Te6edf3SECONDARY

Tff7b72else Tff7b72-Tff7b72> Te6edf3ChannelTb4b4b4.Te6edf3RoleTb4b4b4.Te6edf3DISABLED
Tb4b4b4}Tb4b4b4,
Te6edf3index Tff7b72= Te6edf3iTb4b4b4,
Te6edf3settings Tff7b72= Te6edf3newTb4b4b4.Te6edf3getOrNullTb4b4b4(Te6edf3iTb4b4b4) Tff7b72?: Te6edf3ChannelSettingsTb4b4b4(Tb4b4b4)Tb4b4b4,
Tb4b4b4)Tb4b4b4,
Tb4b4b4)
Tb4b4b4}
Tb4b4b4}

T8b949e/**
* Normalizes an imported REPLACE-mode [ChannelSettings] list so firmware only materializes real, distinct channels.
*
* Imported replacement sets can carry blank placeholder secondaries (trailing empty [ChannelSettings] padding) and
* semantic duplicates (two slots resolving to the same effective channel under the active LoRa preset). Both produce
* invalid LongFast-looking slots on the radio that cause route failures (`QueueStatus res=6` / `routeErr=6`).
* - Slot 0 (primary) is always preserved as-is, even if blank (a blank primary is a deliberate disable signal).
* - A blank placeholder primary does not participate in duplicate tracking.
* - Blank placeholder secondaries (no name AND no PSK) are dropped.
* - Semantic duplicates (same effective name + effective PSK as an earlier kept slot) are dropped.
* - Remaining valid secondaries compact into sequential slots 1..n.
*
* @param settings Raw imported settings list.
* @param loraConfig Active LoRa config used to resolve effective channel identity. Null falls back to defaults.
* @return Compacted, deduplicated list safe to write to the radio.
*/
Tff7b72fun Td2a8ffnormalizeReplacementSettingsTb4b4b4(
Te6edf3settingsTb4b4b4: Te6edf3ListTff7b72<Te6edf3ChannelSettingsTff7b72>Tb4b4b4,
Te6edf3loraConfigTb4b4b4: Te6edf3ConfigTb4b4b4.Te6edf3LoRaConfigTff7b72?Tb4b4b4,
Tb4b4b4)Tb4b4b4: Te6edf3ListTff7b72<Te6edf3ChannelSettingsTff7b72> Tb4b4b4{
Tff7b72if Tb4b4b4(Te6edf3settingsTb4b4b4.Te6edf3size Tff7b72<Tff7b72= T79c0ff1Tb4b4b4) Tff7b72return Te6edf3settings
Tff7b72val Te6edf3effectiveLora Tff7b72= Te6edf3loraConfig Tff7b72?: Te6edf3ConfigTb4b4b4.Te6edf3LoRaConfigTb4b4b4(Tb4b4b4)
Tff7b72val Te6edf3primary Tff7b72= Te6edf3settingsTb4b4b4.Te6edf3firstTb4b4b4(Tb4b4b4)
Tff7b72val Te6edf3seen Tff7b72= Te6edf3mutableSetOfTff7b72<Te6edf3ChannelIdentityTff7b72>Tb4b4b4(Tb4b4b4)
Tff7b72if Tb4b4b4(Tff7b72!Te6edf3primaryTb4b4b4.Te6edf3isPlaceholderTb4b4b4(Tb4b4b4)Tb4b4b4) Tb4b4b4{
Te6edf3seenTb4b4b4.Te6edf3addTb4b4b4(Te6edf3primaryTb4b4b4.Te6edf3channelIdentityTb4b4b4(Te6edf3effectiveLoraTb4b4b4)Tb4b4b4)
Tb4b4b4}
Tff7b72val Te6edf3compact Tff7b72= Te6edf3mutableListOfTb4b4b4(Te6edf3primaryTb4b4b4)
Tff7b72for Tb4b4b4(Te6edf3index Tff7b72in T79c0ff1.Tb4b4b4.Te6edf3settingsTb4b4b4.Te6edf3lastIndexTb4b4b4) Tb4b4b4{
Tff7b72val Te6edf3candidate Tff7b72= Te6edf3settingsTff7b72[Te6edf3indexTff7b72]
Tff7b72val Te6edf3identity Tff7b72= Tff7b72if Tb4b4b4(Te6edf3candidateTb4b4b4.Te6edf3isPlaceholderTb4b4b4(Tb4b4b4)Tb4b4b4) Tff7b72null Tff7b72else Te6edf3candidateTb4b4b4.Te6edf3channelIdentityTb4b4b4(Te6edf3effectiveLoraTb4b4b4)
Tff7b72if Tb4b4b4(Te6edf3identity Tff7b72!Tff7b72= Tff7b72null Tff7b72&Tff7b72& Te6edf3seenTb4b4b4.Te6edf3addTb4b4b4(Te6edf3identityTb4b4b4)Tb4b4b4) Tb4b4b4{
Te6edf3compactTb4b4b4.Te6edf3addTb4b4b4(Te6edf3candidateTb4b4b4)
Tb4b4b4}
Tb4b4b4}
Tff7b72return Te6edf3compact
Tb4b4b4}

T8b949e/** True when a [ChannelSettings] carries no name and no PSK β€” a placeholder, not an intended channel. */
Tff7b72private Tff7b72fun Te6edf3ChannelSettingsTb4b4b4.Td2a8ffisPlaceholderTb4b4b4(Tb4b4b4)Tb4b4b4: Tffa657Boolean Tff7b72= Te6edf3nameTb4b4b4.Te6edf3isNullOrBlankTb4b4b4(Tb4b4b4) Tff7b72&Tff7b72& Te6edf3pskTb4b4b4.Te6edf3size Tff7b72=Tff7b72= T79c0ff0

T8b949e/**
* Imports a [ChannelSet] as an authoritative REPLACE: writes every channel and β€” when present and actually different β€”
* the imported LoRa config, all inside one [RadioController.editLocalSettings] transaction, then replaces the local
* channel cache.
*
* Reads the current LoRa config and channel set from [radioConfigRepository]'s flows (avoiding the StateFlow
* placeholder window) and builds the authoritative replacement list via [getChannelReplacementList]. The edit-settings
* transaction defers disk persistence, radio reload/reconfiguration, and reboot until the closing commit, so channels +
* LoRa land in a single reboot with no per-slot reconfigure to pace against. (Firmware still writes each `set_channel`
* into its in-memory channel table as it arrives β€” the transaction is not a full staging of channel state β€” but the
* expensive persist/reload path runs once at commit.) Writing LoRa inside the same session mirrors
* `InstallProfileUseCase` and is why the old pre/post settle delays are gone: the begin/commit boundary is the settle.
*
* The local channel cache is commit-shaped: transactional channel writes deliberately do not mirror per slot (see
* `AdminControllerImpl.EditSettingsSession.setChannel`), and this function replaces the cached channel list once, after
* the session succeeds β€” so an import interrupted before that point leaves the local channel cache untouched. (The
* imported LoRa config is the one exception: it still writes through the cache-mirroring `setConfig`, so its local
* cache update is not itself deferred to commit β€” a single trailing write that self-heals on the device's next config
* re-send. Making `setConfig` transaction-aware is future work.)
*
* Imported settings are normalized via [normalizeReplacementSettings] before any write or bounds check, so blank
* placeholder secondaries and semantic duplicates never reach the radio or the local cache.
*
* @param channelSet The imported [ChannelSet] to apply as a replacement. Its `lora_config`, if present and different
* from the device's current LoRa config, is written inside the same transaction.
* @param radioController The [RadioController] used to run the edit transaction.
* @param radioConfigRepository The [RadioConfigRepository] providing the current channel/LoRa flows and cache.
*/
Tff7b72suspend Tff7b72fun Td2a8ffimportChannelSetTb4b4b4(
Te6edf3channelSetTb4b4b4: Te6edf3ChannelSetTb4b4b4,
Te6edf3radioControllerTb4b4b4: Te6edf3RadioControllerTb4b4b4,
Te6edf3radioConfigRepositoryTb4b4b4: Te6edf3RadioConfigRepositoryTb4b4b4,
Tb4b4b4) Tb4b4b4{
T8b949e// Resolve the LoRa preset used for semantic identity: prefer the imported config, fall back to the device's current
T8b949e// local config so duplicate detection stays correct when the import omits lora_config (e.g. a non-default preset).
Tff7b72val Te6edf3currentLoraConfig Tff7b72= Te6edf3radioConfigRepositoryTb4b4b4.Te6edf3localConfigFlowTb4b4b4.Te6edf3firstTb4b4b4(Tb4b4b4)Tb4b4b4.Te6edf3lora
Tff7b72val Te6edf3identityLoraConfig Tff7b72= Te6edf3channelSetTb4b4b4.Te6edf3lora_config Tff7b72?: Te6edf3currentLoraConfig
Tff7b72val Te6edf3normalizedSettings Tff7b72= Te6edf3normalizeReplacementSettingsTb4b4b4(Te6edf3channelSetTb4b4b4.Te6edf3settingsTb4b4b4, Te6edf3identityLoraConfigTb4b4b4)
Te6edf3requireTb4b4b4(Te6edf3normalizedSettingsTb4b4b4.Te6edf3size Tff7b72<Tff7b72= Te6edf3CHANNEL_REPLACEMENT_SLOT_COUNTTb4b4b4) Tb4b4b4{
Ta5d6ff"Ta5d6ffImported channel set exceeds supported channel slot countTa5d6ff"
Tb4b4b4}
Tff7b72val Te6edf3currentSettings Tff7b72= Te6edf3radioConfigRepositoryTb4b4b4.Te6edf3channelSetFlowTb4b4b4.Te6edf3firstTb4b4b4(Tb4b4b4)Tb4b4b4.Te6edf3settings
Tff7b72val Te6edf3replacements Tff7b72=
Te6edf3getChannelReplacementListTb4b4b4(
Te6edf3new Tff7b72= Te6edf3normalizedSettingsTb4b4b4,
Te6edf3currentSettings Tff7b72= Te6edf3currentSettingsTb4b4b4,
Te6edf3minimumSlotCount Tff7b72= Te6edf3CHANNEL_REPLACEMENT_SLOT_COUNTTb4b4b4,
Te6edf3maximumSlotCount Tff7b72= Te6edf3CHANNEL_REPLACEMENT_SLOT_COUNTTb4b4b4,
Tb4b4b4)
T8b949e// Only write LoRa when the import carries one that actually differs from the device β€” avoids a redundant
T8b949e// reconfigure.
Tff7b72val Te6edf3importedLoraConfig Tff7b72= Te6edf3channelSetTb4b4b4.Te6edf3lora_configTff7b72?.Te6edf3takeIf Tb4b4b4{ Tffa657it Tff7b72!Tff7b72= Te6edf3currentLoraConfig Tb4b4b4}
Te6edf3LoggerTb4b4b4.Te6edf3i Tb4b4b4{
Ta5d6ff"Ta5d6ffApplying imported channel replacement writes=Tffd700${Te6edf3replacementsTb4b4b4.Te6edf3sizeTffd700}Ta5d6ff Ta5d6ff" Tff7b72+
Ta5d6ff"Ta5d6ffimportedSettings=Tffd700${Te6edf3channelSetTb4b4b4.Te6edf3settingsTb4b4b4.Te6edf3sizeTffd700}Ta5d6ff normalizedSettings=Tffd700${Te6edf3normalizedSettingsTb4b4b4.Te6edf3sizeTffd700}Ta5d6ff Ta5d6ff" Tff7b72+
Ta5d6ff"Ta5d6ffwritesLora=Tffd700${Te6edf3importedLoraConfig Tff7b72!Tff7b72= Tff7b72nullTffd700}Ta5d6ff"
Tb4b4b4}
Te6edf3radioControllerTb4b4b4.Te6edf3editLocalSettings Tb4b4b4{
Tff7b72for Tb4b4b4(Te6edf3channel Tff7b72in Te6edf3replacementsTb4b4b4) Tb4b4b4{
Te6edf3LoggerTb4b4b4.Te6edf3i Tb4b4b4{
Ta5d6ff"Ta5d6ffWriting imported channel index=Tffd700${Te6edf3channelTb4b4b4.Te6edf3indexTffd700}Ta5d6ff role=Tffd700${Te6edf3channelTb4b4b4.Te6edf3roleTffd700}Ta5d6ff Ta5d6ff" Tff7b72+
Ta5d6ff"Ta5d6ffhasName=Tffd700${Te6edf3channelTb4b4b4.Te6edf3settingsTff7b72?.Te6edf3nameTff7b72?.Te6edf3isNotBlankTb4b4b4(Tb4b4b4) Tff7b72=Tff7b72= Tff7b72trueTffd700}Ta5d6ff"
Tb4b4b4}
Te6edf3setChannelTb4b4b4(Te6edf3channelTb4b4b4)
Tb4b4b4}
Te6edf3importedLoraConfigTff7b72?.Te6edf3let Tb4b4b4{ Te6edf3setConfigTb4b4b4(Te6edf3ConfigTb4b4b4(Te6edf3lora Tff7b72= Tffa657itTb4b4b4)Tb4b4b4) Tb4b4b4}
Tb4b4b4}
Te6edf3withContextTb4b4b4(Te6edf3NonCancellableTb4b4b4) Tb4b4b4{ Te6edf3radioConfigRepositoryTb4b4b4.Te6edf3replaceAllSettingsTb4b4b4(Te6edf3normalizedSettingsTb4b4b4) Tb4b4b4}
Tb4b4b4}

T8b949e/**
* Builds the filtered ADD-mode preview for QR import: existing channels followed by only the unique incoming channels.
*
* Incoming channels that are semantic duplicates (same effective name + effective PSK) of an existing or earlier
* incoming channel are omitted from the preview. Unique incoming channels are appended in scanned order and selected by
* default while firmware channel capacity remains; unique channels beyond [maxChannels] stay visible but unchecked.
*
* Semantic identity is resolved via the [Channel] domain model so preset/default channels match correctly across modem
* presets: empty names resolve to the preset display name, and 1-byte PSK markers expand to the full default key.
*
* @param existing The current [ChannelSettings] list on the radio. Always shown, always selected.
* @param incoming The imported [ChannelSettings] list. Duplicates omitted; uniques appended in order.
* @param loraConfig The current [Config.LoRaConfig], used to resolve effective channel identity.
* @param maxChannels Firmware channel limit. Unique incoming selections stop when this is reached.
* @return A [ChannelAddPreview] whose [settings] and [selections] are aligned and size-matched.
*/
Tff7b72fun Td2a8ffgetChannelPreviewForAddTb4b4b4(
Te6edf3existingTb4b4b4: Te6edf3ListTff7b72<Te6edf3ChannelSettingsTff7b72>Tb4b4b4,
Te6edf3incomingTb4b4b4: Te6edf3ListTff7b72<Te6edf3ChannelSettingsTff7b72>Tb4b4b4,
Te6edf3loraConfigTb4b4b4: Te6edf3ConfigTb4b4b4.Te6edf3LoRaConfigTb4b4b4,
Te6edf3maxChannelsTb4b4b4: Tffa657IntTb4b4b4,
Tb4b4b4)Tb4b4b4: Te6edf3ChannelAddPreview Tb4b4b4{
Tff7b72val Te6edf3seen Tff7b72= Te6edf3existingTb4b4b4.Te6edf3map Tb4b4b4{ Tffa657itTb4b4b4.Te6edf3channelIdentityTb4b4b4(Te6edf3loraConfigTb4b4b4) Tb4b4b4}Tb4b4b4.Te6edf3toMutableSetTb4b4b4(Tb4b4b4)
Tff7b72val Te6edf3previewSettings Tff7b72= Te6edf3existingTb4b4b4.Te6edf3toMutableListTb4b4b4(Tb4b4b4)
Tff7b72val Te6edf3previewSelections Tff7b72= Te6edf3MutableListTb4b4b4(Te6edf3existingTb4b4b4.Te6edf3sizeTb4b4b4) Tb4b4b4{ Tff7b72true Tb4b4b4}
Tff7b72var Te6edf3remaining Tff7b72= Tb4b4b4(Te6edf3maxChannels Tff7b72- Te6edf3existingTb4b4b4.Te6edf3sizeTb4b4b4)Tb4b4b4.Te6edf3coerceAtLeastTb4b4b4(T79c0ff0Tb4b4b4)
Tff7b72for Tb4b4b4(Te6edf3channel Tff7b72in Te6edf3incomingTb4b4b4) Tb4b4b4{
Tff7b72val Te6edf3shouldShow Tff7b72= Tff7b72!Te6edf3channelTb4b4b4.Te6edf3isPlaceholderTb4b4b4(Tb4b4b4)
Tff7b72val Te6edf3identity Tff7b72= Tff7b72if Tb4b4b4(Te6edf3shouldShowTb4b4b4) Te6edf3channelTb4b4b4.Te6edf3channelIdentityTb4b4b4(Te6edf3loraConfigTb4b4b4) Tff7b72else Tff7b72null
T8b949e// Omit blank placeholders and semantic duplicates entirely β€” they are not shown to the user.
Tff7b72if Tb4b4b4(Te6edf3identity Tff7b72!Tff7b72= Tff7b72null Tff7b72&Tff7b72& Te6edf3seenTb4b4b4.Te6edf3addTb4b4b4(Te6edf3identityTb4b4b4)Tb4b4b4) Tb4b4b4{
Te6edf3previewSettings Tff7b72+Tff7b72= Te6edf3channel
Tff7b72val Te6edf3shouldSelect Tff7b72= Te6edf3remaining Tff7b72> T79c0ff0
Te6edf3previewSelections Tff7b72+Tff7b72= Te6edf3shouldSelect
Tff7b72if Tb4b4b4(Te6edf3shouldSelectTb4b4b4) Te6edf3remainingTff7b72-Tff7b72-
Tb4b4b4}
Tb4b4b4}
Tff7b72return Te6edf3ChannelAddPreviewTb4b4b4(Te6edf3settings Tff7b72= Te6edf3previewSettingsTb4b4b4, Te6edf3selections Tff7b72= Te6edf3previewSelectionsTb4b4b4)
Tb4b4b4}

T8b949e/** Filtered ADD-mode preview: the visible channel list paired with its default selections (always size-matched). */
Tff7b72data Tff7b72class T56d364ChannelAddPreviewTb4b4b4(Tff7b72val Te6edf3settingsTb4b4b4: Te6edf3ListTff7b72<Te6edf3ChannelSettingsTff7b72>Tb4b4b4, Tff7b72val Te6edf3selectionsTb4b4b4: Te6edf3ListTff7b72<Tffa657BooleanTff7b72>Tb4b4b4)

T8b949e/** Semantic channel identity based on effective name and effective PSK. */
Tff7b72private Tff7b72data Tff7b72class T56d364ChannelIdentityTb4b4b4(Tff7b72val Te6edf3nameTb4b4b4: Tffa657StringTb4b4b4, Tff7b72val Te6edf3pskTb4b4b4: Te6edf3ByteStringTb4b4b4) Tb4b4b4{
T8b949e// Redact the effective PSK from auto-generated diagnostics so a cryptographic key never leaks
T8b949e// via toString() in exception messages, debug logs, or stack traces.
Tff7b72override Tff7b72fun Td2a8fftoStringTb4b4b4(Tb4b4b4)Tb4b4b4: Tffa657String Tff7b72= Ta5d6ff"Ta5d6ffChannelIdentity(name=Tffd700$Te6edf3nameTa5d6ff, psk=<redacted>)Ta5d6ff"
Tb4b4b4}

T8b949e/** Resolves the [ChannelIdentity] of this [ChannelSettings] under the given [Config.LoRaConfig]. */
Tff7b72private Tff7b72fun Te6edf3ChannelSettingsTb4b4b4.Td2a8ffchannelIdentityTb4b4b4(Te6edf3loraConfigTb4b4b4: Te6edf3ConfigTb4b4b4.Te6edf3LoRaConfigTb4b4b4)Tb4b4b4: Te6edf3ChannelIdentity Tb4b4b4{
Tff7b72val Te6edf3channel Tff7b72= Te6edf3ModelChannelTb4b4b4(Te6edf3settings Tff7b72= Tff7b72thisTb4b4b4, Te6edf3loraConfig Tff7b72= Te6edf3loraConfigTb4b4b4)
Tff7b72return Te6edf3ChannelIdentityTb4b4b4(Te6edf3name Tff7b72= Te6edf3channelTb4b4b4.Te6edf3nameTb4b4b4, Te6edf3psk Tff7b72= Te6edf3channelTb4b4b4.Te6edf3pskTb4b4b4)
Tb4b4b4}

Served by rngit 1.5.0 - Generated in 0.1s